package com.haoze.nurseapp.controller;

import com.haoze.common.response.Result;
import com.haoze.common.response.ResultGenerator;
import com.haoze.nurseapp.dto.MedicineApplyDTO;
import com.haoze.nurseapp.dto.PrescApplyDTO;
import com.haoze.nurseapp.service.MedicineApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.POST;
import java.util.List;
import java.util.Map;

/**
 * @author lufq
 * @date 2020/9/17
 */
@RestController
@RequestMapping(value = "/nurseapp/medicineapply")
@Api(value = "pc端领药")
public class MedicineApplyController {
    @Autowired
    private MedicineApplyService medicineApplyService;
    /**
     * 患者待领药列表
     * @param wardDeptId
     * @param type
     * @return
     */
    @GetMapping("/waitMedicineList")
    @ApiOperation(value = "患者待领药列表")
    public Result waitMedicineList(@RequestParam String wardDeptId,@RequestParam String type,
                                   @RequestParam Integer pageNum,@RequestParam Integer pageSize,
                                   @RequestParam String inpatList,
                                   @RequestParam String status,
                                   @RequestParam(required = false) String pharmacy) {
        medicineApplyService.updateDrugApplyMainStatus();
        //全部
        if("0".equals(status)){
            return medicineApplyService.waitMedicineList(wardDeptId,type,pageNum,pageSize,inpatList);
        }else if("1".equals(status)){
            return medicineApplyService.queryToBeReceivedMedicineList(type,wardDeptId,inpatList,pageNum,pageSize,pharmacy);
        }
        return ResultGenerator.genOkResult();

    }

    /**
     * 根据病区id获取药房列表
     * @param wardDeptId
     * @return
     */
    @GetMapping("/queryPharmacyByWardDeptId")
    @ApiOperation(value = "获取药房列表")
    public Result queryPharmacyByWardDeptId(@RequestParam String wardDeptId,@RequestParam String flag) {
        return medicineApplyService.queryPharmacyByWardDeptId(wardDeptId,flag);
    }

    /**
     * 保存
     */
    @PostMapping("/saveMedicineApply")
    @ApiOperation(value = "保存")
    public Result saveMedicineApply(@RequestBody MedicineApplyDTO medicineApplyDTO) {
        return medicineApplyService.saveMedicineApply(medicineApplyDTO);
    }

    /**
     * 病区领药确认提示
     */
    @PostMapping("/confirmTips")
    @ApiOperation(value = "病区领药")
    public Result confirmTips(@RequestBody MedicineApplyDTO medicineApplyDTO) {
        return medicineApplyService.confirmTips(medicineApplyDTO);
    }

    @DeleteMapping("/deleteMedicineApply")
    @ApiOperation(value = "删除领药申请")
    public Result deleteMedicineApply(@RequestParam String applyIdList,@RequestParam String type) {
        return medicineApplyService.deleteMedicineApply(applyIdList,type);
    }

    @GetMapping("/queryPatientPresc")
    @ApiOperation(value = "获取所有的处方记录")
    public Result queryPatientPresc(@RequestParam String inpatNum,@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "20") int pageSize) {
        medicineApplyService.updateDrugApplyMainStatus();
        return medicineApplyService.queryPatientPresc(inpatNum,page,pageSize);
    }

    @GetMapping("/queryPatientPrescDetail")
    @ApiOperation(value = "根据处方号获取处方明细")
    public Result queryPatientPrescDetail(@RequestParam String prescNums) {
        return medicineApplyService.queryPatientPrescDetail(prescNums);
    }

    @GetMapping("/noCompleteOrders")
    @ApiOperation(value = "未领药完毕的医嘱")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = " 查询类型：1主表 2明细", dataType = "String", paramType = "wardId")
    })
    public Result noCompleteOrders(@RequestParam String inpatNum,@RequestParam String type,@RequestParam(required = false) String orderId) {
        return medicineApplyService.noCompleteOrders(inpatNum,type,orderId);
    }

    @PostMapping("/savePrescription")
    @ApiOperation(value = "保存/取消处方申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = " 查询类型：1主表 2明细", dataType = "String", paramType = "wardId")
    })
    public Result savePrescription(@RequestBody PrescApplyDTO prescApplyDTO) {
        medicineApplyService.updateDrugApplyMainStatus();
        return medicineApplyService.savePrescription(prescApplyDTO);
    }

    @GetMapping("/confirmPatientPresc")
    @ApiOperation(value = "护士确认处方")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "prescNums", value = "处方号", dataType = "String", paramType = "prescNums"),
            @ApiImplicitParam(name = "confirmFlag", value = "0 不勾选 1勾选", dataType = "String", paramType = "confirmFlag"),
    })
    public Result confirmPatientPresc(@RequestParam String prescNums,@RequestParam String confirmFlag){
        return medicineApplyService.confirmPatientPresc(prescNums,confirmFlag);
    }

}
